package com.zxy.ziems.server.monitor.controller;

import com.zxy.ziems.server.monitor.pojo.dto.MonitorGroupAddDTO;
import com.zxy.ziems.server.monitor.pojo.vo.MonitorGroupVO;
import com.zxy.ziems.server.monitor.pojo.vo.MonitorTreeVO;
import com.zxy.ziems.server.monitor.service.MonitorGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 监控组
 *
 * @Copyright (C),
 * @ClassName: MonitorGroupController
 * @Author: yanzhiwei
 * @Description:
 * @Date: 2024/5/10 15:25
 */
@RestController
@Validated
@RequestMapping("/api/monitor/group")
public class MonitorGroupController {


    /**
     * 监控组列表
     *
     * @return
     */
    @GetMapping("/list")
    public List<MonitorGroupVO> page() throws Exception {
        return service.getGroupList();
    }


    /**
     * 监控组,监控设备树
     *
     * @return
     */
    @GetMapping("/devideTree")
    public List<MonitorTreeVO> devideTree() {
        return service.devideTree();
    }


    /**
     * 监控组添加
     *
     * @return
     */
    @PostMapping("/add")
    public boolean addGroup(@Validated(value = MonitorGroupAddDTO.Add.class) @RequestBody MonitorGroupAddDTO monitorGroupAddDTO) {
        return service.addGroup(monitorGroupAddDTO);
    }

    /**
     * 监控组修改
     *
     * @return
     */
    @PostMapping("/update")
    public boolean updateGroup(@Validated(value = MonitorGroupAddDTO.Update.class) @RequestBody MonitorGroupAddDTO monitorGroupAddDTO) {
        return service.updateGroup(monitorGroupAddDTO);
    }

    /**
     * 监控组删除
     *
     * @return
     */
    @PostMapping("/delete")
    public boolean deleteGroup(@Validated(value = MonitorGroupAddDTO.Select.class) @RequestBody MonitorGroupAddDTO monitorGroupAddDTO) {
        return service.deleteGroup(monitorGroupAddDTO.getId());
    }


    private MonitorGroupService service;

    @Autowired
    public void setService(MonitorGroupService monitorGroupService) {
        this.service = monitorGroupService;
    }
}
